package com.yanqu.road.server.cmd.activity.summergames;

import com.yanqu.road.entity.activity.summergames.SummerGamesConfig;
import com.yanqu.road.entity.activity.summergames.SummerGamesUserData;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SummerGamesProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.summergames.SummerGamesModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.summergames.SummerGamesActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;

@Cmd(code = Protocol.S_SUMMER_GAMES_GET_GUESS_ITEM, desc = "领取竞猜币")
@CmdApi(reqMsg = SummerGamesProto.SummerGamesGetDayGuessItemReqMsg.class, respMsg = SummerGamesProto.SummerGamesGetDayGuessItemRespMsg.class)
public class SummerGamesGetDayGuessItemCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

//        SummerGamesConfig config = SummerGamesActivityMgr.getSummerGamesConfig();
//        // 没有活动
//        if (config == null || !ActivityMgr.activityInTime(config.getActivityInfo())) {
//            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
//            return;
//        }
//
//        SummerGamesUserData userData = player.getModule(SummerGamesModule.class).getUserData();
//        if(userData == null){
//            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
//            return;
//        }
//
//        long zeroTimeStamp = DateHelper.getTodayZeroTimeStamp();
//        if(userData.getDayGetGuessItemMap().containsKey(zeroTimeStamp)){
//            ret = GameErrorCode.E_SUMMER_GAMES_GUESS_ITEM_TODAY_GOT;
//            return;
//        }
//
//        userData.getDayGetGuessItemMap().put(zeroTimeStamp, 1);
//        userData.setUpdateOption();
//
//        Property reward = new Property();
//        reward.addProperty(config.getEXCHANGE_SCORE_ITEM_ID_1(), BigInteger.valueOf(config.getQUIZ_SCORE_DAILY_RECEIVE()));
//        player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.SummerGamesActivity, eLogMoneyType.SummerGamesActivityDailyQuizReward);
//
//        SummerGamesProto.SummerGamesGetDayGuessItemRespMsg.Builder builder = SummerGamesProto.SummerGamesGetDayGuessItemRespMsg.newBuilder().setRet(0);
//        builder.setReward(PropertyHelper.parsePropertyToString(reward));
//        player.sendPacket(Protocol.U_SUMMER_GAMES_GET_GUESS_ITEM, builder);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_SUMMER_GAMES_GET_GUESS_ITEM, SummerGamesProto.SummerGamesGetDayGuessItemRespMsg.newBuilder().setRet(ret));
        }
    }
}
